package action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import entitybean.l_sequence.EntityBeanL_Sequence;
import entitybean.oc_depthlist.EntityBeanOc_Depthlist;
import entitybean.oc_depthlist_ben.EntityBeanOc_Depthlist_Ben;
import form.DepthBenForm;
import form.DepthForm;
import service.service_admin.Service_Admin;
import service.service_public.Service_Public;
import tools.InterfaceForResultSetToList;
import tools.PageBeanPlus;
import view.ViewOc_Boat_Ben;
import view.ViewOc_Depth;
import view.ViewOc_Depth_Ben;

public class Action_Oc_Depthlist_Ben extends DispatchAction{
	private Service_Admin service_admin;
	private Service_Public service_public;
	public Service_Admin getService_admin() {
		return service_admin;
	}

	public void setService_admin(Service_Admin serviceAdmin) {
		service_admin = serviceAdmin;
	}

	public Service_Public getService_public() {
		return service_public;
	}

	public void setService_public(Service_Public servicePublic) {
		service_public = servicePublic;
	}

	public ActionForward admin_init_oc_depthlist_ben(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		DepthBenForm depthbenform = (DepthBenForm) form;
		System.out.println("初始化底栖生物层深");
		String sql = "select ID,DEPTH from OC_DEPTHLIST_BEN where DEL='OFF'";
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(depthbenform.getRowcountperpage()), Integer
						.valueOf(depthbenform.getCurrentpage()), "loadrichtext()");
		InterfaceForResultSetToList interfaceforresultsettolist = new InterfaceForResultSetToList();
		List<ViewOc_Depth_Ben> list = interfaceforresultsettolist
				.ViewOc_Depth_Ben(pagebeanplus.getFormatqueryresultset());

		request.setAttribute("pagebeanplus", pagebeanplus);// 设置传递到页面的数据
		request.setAttribute("list", list);
		request.setAttribute("depthbenform", depthbenform);
		System.out.println("list.size()" + list.size());
		return mapping.findForward("success");

	}

	public ActionForward admin_load_oc_depthlist_ben(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		DepthBenForm depthbenform = (DepthBenForm) form;
		String id = depthbenform.getId();
		EntityBeanOc_Depthlist_Ben e = this.service_admin.Find_Oc_Depthlist_Ben_By_id(id);
		request.setAttribute("e", e);
		return mapping.findForward("success");
	}

	public ActionForward admin_add_oc_depthlist_ben(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		System.out.println("准备添加一个底栖生物的深度");
		return mapping.findForward("success");
	}

	public ActionForward admin_insert_oc_depthlist_ben(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		DepthBenForm depthbenform = (DepthBenForm) form;
		String depth = depthbenform.getDepth();
		EntityBeanL_Sequence l = this.service_public
				.Find_L_Sequence_By_seq_Name("SEQ_OC_DEPTHLIST_BEN");
		Integer id = l.getSeq_Value() + 1;
		l.setSeq_Value(id);
		EntityBeanOc_Depthlist_Ben e = new EntityBeanOc_Depthlist_Ben();
		e.setDel("OFF");
		e.setId(id);
		e.setDepth(Integer.valueOf(depth));
		
		this.service_public.Update_L_Sequence(l);
		this.service_admin.Insert_Oc_Depthlist_Ben(e);

		
		String sql = "select ID,DEPTH from OC_DEPTHLIST_BEN where DEL='OFF'";
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(depthbenform.getRowcountperpage()), Integer
						.valueOf(depthbenform.getCurrentpage()), "loadrichtext()");
		InterfaceForResultSetToList interfaceforresultsettolist = new InterfaceForResultSetToList();
		List<ViewOc_Depth_Ben> list = interfaceforresultsettolist
				.ViewOc_Depth_Ben(pagebeanplus.getFormatqueryresultset());

		request.setAttribute("pagebeanplus", pagebeanplus);// 设置传递到页面的数据
		request.setAttribute("list", list);
		request.setAttribute("depthbenform", depthbenform);
		System.out.println("list.size()" + list.size());
		return mapping.findForward("success");
	}

	public ActionForward admin_delete_oc_depthlist_ben(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		System.out.println("删除海洋环境层深");
		DepthBenForm depthbenform = (DepthBenForm) form;
		String id = depthbenform.getId();
		id = this.cut_tail(id);
		this.service_admin.Delete_Oc_Depthlist_Ben(id);
		String sql = "select ID,DEPTH from OC_DEPTHLIST_BEN where DEL='OFF'";
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(depthbenform.getRowcountperpage()), Integer
						.valueOf(depthbenform.getCurrentpage()), "loadrichtext()");
		InterfaceForResultSetToList interfaceforresultsettolist = new InterfaceForResultSetToList();
		List<ViewOc_Depth_Ben> list = interfaceforresultsettolist
				.ViewOc_Depth_Ben(pagebeanplus.getFormatqueryresultset());

		request.setAttribute("pagebeanplus", pagebeanplus);// 设置传递到页面的数据
		request.setAttribute("list", list);
		request.setAttribute("depthbenform", depthbenform);
		System.out.println("list.size()" + list.size());
		return mapping.findForward("success");
	}

	public ActionForward admin_update_oc_depthlist_ben(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		DepthBenForm depthbenform = (DepthBenForm) form;
		String id = depthbenform.getId();
		String depth = depthbenform.getDepth();
		EntityBeanOc_Depthlist_Ben e = this.service_admin.Find_Oc_Depthlist_Ben_By_id(id);
		e.setDepth(Integer.valueOf(depth));
		this.service_admin.Update_Oc_Depthlist_Ben(e);

		String sql = "select ID,DEPTH from OC_DEPTHLIST_BEN where DEL='OFF'";
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(depthbenform.getRowcountperpage()), Integer
						.valueOf(depthbenform.getCurrentpage()), "loadrichtext()");
		InterfaceForResultSetToList interfaceforresultsettolist = new InterfaceForResultSetToList();
		List<ViewOc_Depth_Ben> list = interfaceforresultsettolist
				.ViewOc_Depth_Ben(pagebeanplus.getFormatqueryresultset());

		request.setAttribute("pagebeanplus", pagebeanplus);// 设置传递到页面的数据
		request.setAttribute("list", list);
		request.setAttribute("depthbenform", depthbenform);
		System.out.println("list.size()" + list.size());

		return mapping.findForward("success");
	}

	public ActionForward admin_search_oc_depthlist_ben(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		
		DepthBenForm depthbenform = (DepthBenForm) form;
		String sql = "select ID,DEPTH from OC_DEPTHLIST_BEN where DEL='OFF'";
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(depthbenform.getRowcountperpage()), Integer
						.valueOf(depthbenform.getCurrentpage()), "loadrichtext()");
		InterfaceForResultSetToList interfaceforresultsettolist = new InterfaceForResultSetToList();
		List<ViewOc_Depth_Ben> list = interfaceforresultsettolist
				.ViewOc_Depth_Ben(pagebeanplus.getFormatqueryresultset());

		request.setAttribute("pagebeanplus", pagebeanplus);// 设置传递到页面的数据
		request.setAttribute("list", list);
		request.setAttribute("depthbenform", depthbenform);
		System.out.println("list.size()" + list.size());
		return mapping.findForward("success");
		
		
	
	}

	private String cut_tail(String str) {
		String cut = str;
		if (str.endsWith(",")) {
			cut = cut.substring(0, cut.length() - 1);
		}
		return cut;
	}
}
